package com.chang.soul.service.imp;

import com.chang.soul.bean.AdminBean;
import com.chang.soul.dao.AdminMapper;
import com.chang.soul.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class AdminServiceImp implements AdminService {

    /*@Autowired是用在JavaBean中的注解，通过byType形式，用来给指定的字段或方法注入所需的外部资源。*/
    @Autowired
    AdminMapper adminMapper;
    @Override
    public List<AdminBean> getAllAdmin() {
        return adminMapper.getAllAdmin();
    }

    @Override
    public boolean insertAdmin(AdminBean adminBean) {
        try{
            adminMapper.insertAdmin(adminBean);
        }catch (Exception e){
            System.out.println(e);
            return  false;
        }
        return  true;
    }

    @Override
    public boolean deleteAdminById(Integer id) {
       try {
           adminMapper.deleteAdminById(id);
       }catch (Exception e){
           System.out.println(e);
           return  false;
       }
       return true;
    }

    @Override
    public boolean updateAdmin(AdminBean adminBean) {
        try {
            adminMapper.updateAdmin(adminBean);

        }catch (Exception e){
            System.out.println(e);
            return false;
        }
        return true;
    }

    @Override
    public AdminBean getAdminById(Integer id) {
        return adminMapper.getAdminById(id);
    }

    @Override
    public AdminBean getAdminByNickName(String nickName) {
        return adminMapper.getAdminByNickName(nickName);
    }

    @Override
    public int getCountByNickName(String nickName) {
        return adminMapper.getCountByNickName(nickName);
    }

    @Override
    public List<AdminBean> getAdminByCity(String city) {
        return adminMapper.getAdminByCity(city);
    }

}
